<?php
//发布求助
//type 1:求助 2：救护
function get_releaseInfo($log_id,$type){
  $info=array();
  $user_sex=array('未知','男','女');
  if($type==1){
    $rescue_status=array('待救援','救援中','完成救援','已评价','取消');
  }else{
    $rescue_status=array('救援他','救援中','完成救援','已评价','取消');
  }
  
  $sql = "SELECT a.*,b.headimg,b.user_name,b.user_integral,b.sex,b.height,b.weight,b.label,b.user_phone,c.user_id as ruser_id,c.user_name as rescue_name,c.headimg as rescue_headimg FROM " .$GLOBALS['db']->table('rescue_log').
  " AS a LEFT JOIN ".$GLOBALS['db']->table('users').
  " AS b on a.user_id = b.user_id".
  " LEFT JOIN ".$GLOBALS['db']->table('users').
  " AS c on a.rescue_id=c.user_id WHERE a.id='$log_id'";
  
	$res=$GLOBALS['db']->getRow($sql);
	if($res){
		
		$info['log_id']=$res['id'];
		$info['demander_name']=$res['user_name'];
		$info['demander_headimg']=GZ_Api::get_url($res['headimg']);
		$info['demander_integral']=$res['user_integral'];
		//标签
		$info['demander_label']='';
		if(!empty($res['label'])){
			$info['demander_label']=json_decode($res['label']);
		}
		
		if($type==1){
			$info['award_money']=$res['award_money'];//奖励金额
		}else{
			$info['reality_money']=$res['reality_money'];//实付金额
		}
		//定位地址
		$info['address']=isset($res['address'])?$res['address']:'';
		
		//用户特征
		$height=isset($res['height'])?$res['height']:'0.00';
	 	$weight=isset($res['weight'])?$res['weight']:'0.00';
	 	$info['demander_style']=$user_sex[$res['sex']].'  '.$height.'cm  '. $weight.'kg';   
		//救援信息
		if($res['status']>0 ){ //已经有人救援（ 0未救援） 
			 $info['rescue_info']=array(
			// 'rescue_id'=>isset($res['ruser_id'])?$res['ruser_id']:'',
			 'rescue_name'=>isset($res['rescue_name'])?$res['rescue_name']:'',
			 'rescue_headimg'=>GZ_Api::get_url($res['rescue_headimg']),
			 );
		}else{
			$info['demander_phone']=isset($res['user_phone'])?$res['user_phone']:'';
		}
		//情况描述
		$info['incident_desc']=isset($res['incident_desc'])?$res['incident_desc']:'';
		//现场图片
		$info['user_imglist'] = '';
		if(!empty($res['user_imglist'])){
			$info['user_imglist'] = json_decode($res['user_imglist']);
		}
 
		$info['rescue_type'] =get_rescue_typeName($res['rescue_type']);//发布类型
		$info['add_time'] = date('Y-m-d h:i:s',$res['add_time']);
		$info['status'] = $res['status'];
		$info['rescue_status'] = $rescue_status[$res['status']];
		  
	}
	
	return $info;
  
}

/**生成图片相册
 * @param $img_list
 * @return array
 * @author leiying
 */
function create_img_arr($img_list){
    $gallery = array();
    foreach($img_list as $value)
    {
        if(!empty($value)){
            $gallery[]=GZ_api::get_url($value);
        }
    }
    return $gallery;
}
//救护类型名称
function get_rescue_typeName($id){
  $result=$GLOBALS['db']->getOne("select name from ".$GLOBALS['db']->table('rescue_type')." where id='$id'");
  return $result;
}


 
?>